package com.hzg.ssm.web.controller;

import com.hzg.ssm.domain.Department;
import com.hzg.ssm.query.QueryObject;
import com.hzg.ssm.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @ Description: TODO
 * @ Author: 卓哥
 * @ Date: 2020/7/5 18:46
 * @ Version: 1.0
 */
@Controller
@RequestMapping("department")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;
    @RequestMapping("list")
    public String pageList(Model model, @ModelAttribute("qo") QueryObject queryObject){
        System.out.println(queryObject);
        model.addAttribute("pageResult", departmentService.query(queryObject));
        return "department/list";
    }
    @RequestMapping("delete")
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }
    @RequestMapping("input")
    public String input(Long id,Model model){
        if (id!=null){
            model.addAttribute("department",departmentService.select(id) );
        }
        return "department/input";
    }
    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(Department department){
        if (department.getId()!=null){
            departmentService.update(department);
        }
        departmentService.insert(department);
        return "redirect:/department/list.do";
    }
}
